<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户ID" prop="userId">
        <el-input v-model="queryParams.userId" placeholder="请输入用户ID" clearable  />
      </el-form-item>
      <!-- <el-form-item label="订单号" prop="orderNum">
        <el-input v-model="queryParams.orderNum" placeholder="请输入订单号" clearable  />
      </el-form-item> -->
      <el-form-item label="快递单号" prop="payNum">
        <el-input v-model="queryParams.dispatchOrderId" placeholder="请输入支付运费订单号" clearable
           />
      </el-form-item>

      <!-- <el-form-item label="发货批次号" prop="sendNum">
        <el-input v-model="queryParams.sendNum" placeholder="请输入发货批次号" clearable  />
      </el-form-item> -->
      <el-form-item label="收货手机号" prop="goodslistId">
        <el-input v-model="queryParams.phoneNumber" placeholder="请输入收货手机号" clearable
           />
      </el-form-item>

      <el-form-item label="发货状态" prop="title">
        <!-- 状态 -->
        <el-select v-model="queryParams.processStatus" placeholder="请选择发货状态" clearable>
          <el-option label="待发货" value="0" />
          <el-option label="已发货" value="1" />
        </el-select>

      </el-form-item>

      <el-form-item label="发货类型" prop="title">
        <!-- 状态 -->
        <el-select v-model="queryParams.type" placeholder="请选择发货类型" clearable>
          <el-option label="真实发货" value="0" />
          <el-option label="抽赏发货" value="1" />
        </el-select>

      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:list:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:list:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:list:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:list:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="listList" @selection-change="handleSelectionChange"
      @sort-change="dataListSortChangeHandle">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" width="55" align="center" prop="id" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="用户" align="center" prop="username" width="150">
        <template slot-scope="scope">
          <div style="display: flex; align-items: center">
            <el-avatar :src="scope.row.headimg"></el-avatar>
            <div>{{ scope.row.username }}</div>
          </div>
        </template>
      </el-table-column>
      <!-- <el-table-column label="订单号" align="center" prop="orderNum" />
      <el-table-column label="支付运费订单号" align="center" prop="payNum" />
      <el-table-column label="订单id" align="center" prop="orderId" /> -->
      <!-- <el-table-column
        label="商品id"
        sortable="custom"
        align="center"
        prop="goodslistId"
      />
      <el-table-column label="商品封面图" align="center" prop="imgurl">
        <template slot-scope="scope">
          <img :src="scope.row.imgurl" style="width: 50px; height: 50px" />
        </template>
      </el-table-column>
      <el-table-column
        label="商品价格"
        sortable="custom"
        align="center"
        prop="price"
      />-->
      <!-- <el-table-column label="商品名称" align="center" prop="title" /> -->
      <!-- <el-table-column label="下单数量" sortable="custom" align="center" prop="num" />
      <el-table-column label="回收金额" sortable="custom" align="center" prop="outPrice" /> -->
      <el-table-column label="订单状态" align="center" prop="processStatus">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.type == '0'">真实发货</el-tag>
          <el-tag v-if="scope.row.type == '1'">抽赏发货</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="订单状态" align="center" prop="processStatus">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.processStatus == -1">已取消</el-tag>
          <el-tag v-if="scope.row.processStatus == 0">待发货</el-tag>
          <el-tag v-if="scope.row.processStatus == 1" type="success">已发货</el-tag>

        </template>
      </el-table-column>

      <el-table-column label="收货人姓名" align="center" prop="nickName" />
      <el-table-column label="收货人电话" align="center" prop="phoneNumber" />
      <!--   <el-table-column label="省" align="center" prop="province" />
      <el-table-column label="市" align="center" prop="city" />
      <el-table-column label="县 " align="center" prop="county" />
      <el-table-column label="详细地址" align="center" prop="address" />
      <el-table-column label="快递单号" align="center" prop="courierNumber" />
      <el-table-column label="快递名称" align="center" prop="courierName" />
      <el-table-column label="回收时间/发货时间" align="center" prop="endTime" /> -->
      <el-table-column label="快递单号" align="center" prop="dispatchOrderId" />
      <el-table-column label="微信物流号" align="center" prop="realOrderNum" />
      <el-table-column label="订单备注" align="center" prop="message" />
      <!-- <el-table-column label="是否出售 1 是 2 否" align="center" prop="isSale" />
      <el-table-column label="出售时间" align="center" prop="saleTime" /> -->
      <!-- <el-table-column label="商品id" align="center" prop="goodsId" /> -->
      <!-- <el-table-column
        label="订单类型"
        sortable="custom"
        align="center"
        prop="orderType"
      >
        <template slot-scope="scope">
          <el-tag
            :type="
              scope.row.orderType == 1
                ? 'success'
                : scope.row.orderType == 2
                ? 'warning'
                : scope.row.orderType == 3
                ? 'info'
                : scope.row.orderType == 4
                ? 'danger'
                : 'primary'
            "
            >{{
              scope.row.orderType == 1
                ? "下单流程"
                : scope.row.orderType == 2
                ? "集市获得"
                : scope.row.orderType == 3
                ? "积分兑换"
                : scope.row.orderType == 4
                ? "积分抽奖"
                : "未知"
            }}</el-tag
          >
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="0其他 1普通抽奖 2first last w 最终" align="center" prop="kjIs" />
      <el-table-column label="0其他 1普通抽奖 2first last w 最终" align="center" prop="jfKjIs" /> -->
      <!-- <el-table-column label="抽奖序号" align="center" prop="luckNo" />
      <el-table-column label="0否 1是保底" align="center" prop="minType" />
      <el-table-column label="0普通 1无限赏赠送" align="center" prop="give" /> -->
      <!-- <el-table-column label="1保险柜" align="center" prop="insurance" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="creator" /> -->
      <el-table-column label="下单时间" align="center" prop="createTime" width="180" sortable="custom">
        <template slot-scope="scope">
          <span>{{
            scope.row.createTime
          }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:list:edit']">查看详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="fahuo(scope.row)"
            v-hasPermi="['system:list:edit']">发货</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:list:remove']">删除</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleReturnGoods(scope.row)"
            v-hasPermi="['system:list:remove']">退货</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 商品详情 -->
    <el-dialog :title="title" :visible.sync="good_value_is" width="1000px" append-to-body>
      <el-descriptions class="margin-top" title="发货详情" :column="3" :size="size" border>
        <template slot="extra">
          <el-button @click="fahuo(good_value)" type="primary" size="small">发货</el-button>
        </template>
        <!-- <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            发货id
          </template>
          {{ good_value.id }}
        </el-descriptions-item> -->
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            收货人姓名
          </template>
          {{ good_value.nickName }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-mobile-phone"></i>
            手机号
          </template>
          {{ good_value.phoneNumber }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-location-outline"></i>
            订单号
          </template>
          {{ good_value.dispatchOrderId }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-tickets"></i>
            备注
          </template>
          {{ good_value.message }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-office-building"></i>
            联系地址
          </template>
          {{ good_value.address }}
        </el-descriptions-item>
      </el-descriptions>
      <el-table v-if="good_list" :data="good_list" border show-summary style="width: 100%" height="500">
        <el-table-column prop="goodsId" label="商品ID" width="120">
        </el-table-column>
        <!-- <el-table-column prop="goodsListId" label="商品列表ID" width="100">
        </el-table-column> -->
        <el-table-column prop="goodsName" label="商品名称">
          <template slot-scope="scope">
            <div style="display: flex; align-items: center">
              <!-- <el-avatar :src="scope.row.goodsImg"></el-avatar> -->
              <el-image :preview-src-list="[scope.row.goodsImg]" style="width: 60px; height: 60px"
                :src="scope.row.goodsImg" fit="cover"></el-image>
              <div>{{ scope.row.goodsName }}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="goodsPrice" sortable label="商品价格">
        </el-table-column>
        <el-table-column prop="num" sortable label="商品数量">
        </el-table-column>
        <el-table-column prop="total" sortable label="总计">
        </el-table-column>
      </el-table>
    </el-dialog>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 填写订单号 -->
    <el-dialog :title="title" :visible.sync="fahuo_is" width="600px" append-to-body>
      <el-form :model="good_value" label-width="100px" class="demo-dynamic">
        <el-form-item prop="dispatchOrderId" label="快递单号" :rules="[
          { required: true, message: '请输入快递单号', trigger: 'blur' }
        ]">
          <el-input v-model="good_value.dispatchOrderId"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="small" @click="end_fahuo()">发货</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 添加或修改订单明细对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="${comment}" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="订单号" prop="orderNum">
          <el-input v-model="form.orderNum" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="支付运费订单号" prop="payNum">
          <el-input v-model="form.payNum" placeholder="请输入支付运费订单号" />
        </el-form-item>
        <el-form-item label="订单id" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单id" />
        </el-form-item>
        <el-form-item label="商品id" prop="goodslistId">
          <el-input v-model="form.goodslistId" placeholder="请输入商品id" />
        </el-form-item>
        <el-form-item label="商品封面图" prop="imgurl">
          <el-input v-model="form.imgurl" placeholder="请输入商品封面图" />
        </el-form-item>
        <el-form-item label="商品价格" prop="price">
          <el-input v-model="form.price" placeholder="请输入商品价格" />
        </el-form-item>
        <el-form-item label="商品名称" prop="title">
          <el-input v-model="form.title" placeholder="请输入商品名称" />
        </el-form-item>
        <el-form-item label="下单数量" prop="num">
          <el-input v-model="form.num" placeholder="请输入下单数量" />
        </el-form-item>
        <el-form-item label="回收金额" prop="outPrice">
          <el-input v-model="form.outPrice" placeholder="请输入回收金额" />
        </el-form-item>
        <el-form-item label="下单时间" prop="addtime">
          <el-input v-model="form.addtime" placeholder="请输入下单时间" />
        </el-form-item>
        <el-form-item label="收货人姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入收货人姓名" />
        </el-form-item>
        <el-form-item label="收货人电话" prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入收货人电话" />
        </el-form-item>
        <el-form-item label="省" prop="province">
          <el-input v-model="form.province" placeholder="请输入省" />
        </el-form-item>
        <el-form-item label="市" prop="city">
          <el-input v-model="form.city" placeholder="请输入市" />
        </el-form-item>
        <el-form-item label="县 " prop="county">
          <el-input v-model="form.county" placeholder="请输入县 " />
        </el-form-item>
        <el-form-item label="详细地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="快递单号" prop="courierNumber">
          <el-input v-model="form.courierNumber" placeholder="请输入快递单号" />
        </el-form-item>
        <el-form-item label="快递名称" prop="courierName">
          <el-input v-model="form.courierName" placeholder="请输入快递名称" />
        </el-form-item>
        <el-form-item label="回收时间/发货时间" prop="endTime">
          <el-input v-model="form.endTime" placeholder="请输入回收时间/发货时间" />
        </el-form-item>
        <el-form-item label="发货批次号" prop="sendNum">
          <el-input v-model="form.sendNum" placeholder="请输入发货批次号" />
        </el-form-item>
        <el-form-item label="订单备注" prop="message">
          <el-input v-model="form.message" placeholder="请输入订单备注" />
        </el-form-item>
        <el-form-item label="是否出售 1 是 2 否" prop="isSale">
          <el-input v-model="form.isSale" placeholder="请输入是否出售 1 是 2 否" />
        </el-form-item>
        <el-form-item label="出售时间" prop="saleTime">
          <el-input v-model="form.saleTime" placeholder="请输入出售时间" />
        </el-form-item>
        <el-form-item label="商品id" prop="goodsId">
          <el-input v-model="form.goodsId" placeholder="请输入商品id" />
        </el-form-item>
        <el-form-item label="0其他 1普通抽奖 2first last w 最终" prop="kjIs">
          <el-input v-model="form.kjIs" placeholder="请输入0其他 1普通抽奖 2first last w 最终" />
        </el-form-item>
        <el-form-item label="0其他 1普通抽奖 2first last w 最终" prop="jfKjIs">
          <el-input v-model="form.jfKjIs" placeholder="请输入0其他 1普通抽奖 2first last w 最终" />
        </el-form-item>
        <el-form-item label="抽奖序号" prop="luckNo">
          <el-input v-model="form.luckNo" placeholder="请输入抽奖序号" />
        </el-form-item>
        <el-form-item label="0普通 1无限赏赠送" prop="give">
          <el-input v-model="form.give" placeholder="请输入0普通 1无限赏赠送" />
        </el-form-item>
        <el-form-item label="1保险柜" prop="insurance">
          <el-input v-model="form.insurance" placeholder="请输入1保险柜" />
        </el-form-item>
        <el-form-item label="${comment}" prop="creator">
          <el-input v-model="form.creator" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="createDate">
          <el-date-picker clearable v-model="form.createDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import {
  listList,
  getList,
  delList,
  addList,
  updateList,
  deliverGoods, returnGoods, sendByWx
} from '@/api/order/order_list.js'
import { getMy_user } from "@/api/users/user.js";
export default {
  name: "List",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单明细表格数据
      listList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      fahuo_is: false,
      good_value_is: false,
      // 查询参数
      queryParams: {
        isAsc: "desc", // 排序，asc／desc
        orderByColumn: "createTime", // 排序，字段
        pageNum: 1,
        pageSize: 10,
        userId: null,
        orderNum: null,
        payNum: null,
        orderId: null,
        goodslistId: null,
        imgurl: null,
        price: null,
        title: null,
        num: null,
        outPrice: null,
        status: 2,
        addtime: null,
        name: null,
        mobile: null,
        province: null,
        city: null,
        county: null,
        address: null,
        courierNumber: null,
        courierName: null,
        endTime: null,
        sendNum: null,
        message: null,
        isSale: null,
        saleTime: null,
        goodsId: null,
        orderType: null,
        kjIs: null,
        jfKjIs: null,
        luckNo: null,
        minType: null,
        give: null,
        insurance: null,
        creator: null,
        createDate: null,
        type: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderNum: [
          { required: true, message: "订单号不能为空", trigger: "blur" },
        ],
        goodslistId: [
          { required: true, message: "商品id不能为空", trigger: "blur" },
        ],
        imgurl: [
          { required: true, message: "商品封面图不能为空", trigger: "blur" },
        ],
        price: [
          { required: true, message: "商品价格不能为空", trigger: "blur" },
        ],
        title: [
          { required: true, message: "商品名称不能为空", trigger: "blur" },
        ],
        num: [{ required: true, message: "下单数量不能为空", trigger: "blur" }],
        status: [
          {
            required: true,
            message:
              "1 待选择发货 回收  2 待发货  3 已发货 4 已收货 5已回收不能为空",
            trigger: "blur",
          },
        ],
        addtime: [
          { required: true, message: "下单时间不能为空", trigger: "blur" },
        ],
        kjIs: [
          {
            required: true,
            message: "0其他 1普通抽奖 2first last w 最终不能为空",
            trigger: "blur",
          },
        ],
        jfKjIs: [
          {
            required: true,
            message: "0其他 1普通抽奖 2first last w 最终不能为空",
            trigger: "blur",
          },
        ],
        luckNo: [
          { required: true, message: "抽奖序号不能为空", trigger: "blur" },
        ],
        minType: [
          { required: true, message: "0否 1是保底不能为空", trigger: "change" },
        ],
        give: [
          {
            required: true,
            message: "0普通 1无限赏赠送不能为空",
            trigger: "blur",
          },
        ],
        insurance: [
          { required: true, message: "1保险柜不能为空", trigger: "blur" },
        ],
      },
      good_value: false
    };
  },
  created() {
    this.getList();
  },
  methods: {

    //对接微信官方发货接口
    sendByWx(row) {

      sendByWx({
        id: row.id,
        realOrderNum: row.dispatchOrderId,
        dispatchOrderId: this.dispatchOrderId_1,
        transactionId: this.transactionId,
        openId: row.openId
      }).then((response) => {
        this.$message({
          type: "success",
          message: "发货成功!",
        });
        this.fahuo_is = false;
        this.getList();
      }).catch((error) => {
        this.$message({
          type: "error",
          message: error.message,
        });
        this.getList();
      });

    },

    //发货
    fahuo(row) {
      this.good_value = row;
      this.fahuo_is = true;

      if (row.type == 1) {
        this.dispatchOrderId_1 = row.dispatchOrderId.split(',')[0]
        this.transactionId = row.dispatchOrderId.split(',')[1]
      }



      // this.$confirm("是否确认发货", "提示", {
      //   confirmButtonText: "确定",
      //   cancelButtonText: "取消",
      //   type: "warning",
      // })
      //   .then(() => {
      //     this.$message({
      //       type: "success",
      //       message: "发货成功!",
      //     });
      //     this.$router.push({
      //       name: "OrderFa",
      //       params: { id: row.id },
      //     });
      //   })
      //   .catch(() => {
      //     this.$message({
      //       type: "info",
      //       message: "已取消发货",
      //     });
      //   });
    },

    end_fahuo() {
      this.$confirm("是否确认发货", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          if (this.good_value.type == 1) {
            this.sendByWx(this.good_value)
          } else {
            this.good_value.processStatus = 1
            deliverGoods(this.good_value).then((response) => {
              this.$message({
                type: "success",
                message: "发货成功!",
              });
              this.fahuo_is = false;
              this.getList();
            });
          }
          // this.$message({
          //   type: "success",
          //   message: "发货成功!",
          // });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消发货",
          });
        });
    },

    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0 && index === 1) {
          sums[index] = '总价';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] += ' 元';
        } else {
          sums[index] = 'N/A';
        }
      });

      return sums;
    },

    /** 查询订单明细列表 */
    getList() {
      this.loading = true;
      listList(this.queryParams).then((response) => {
        this.listList = response.rows;
        this.queryUser(this.listList);
        console.log(this.listList);
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        orderNum: null,
        payNum: null,
        orderId: null,
        goodslistId: null,
        imgurl: null,
        price: null,
        title: null,
        num: null,
        outPrice: null,
        status: 0,
        addtime: null,
        name: null,
        mobile: null,
        province: null,
        city: null,
        county: null,
        address: null,
        courierNumber: null,
        courierName: null,
        endTime: null,
        sendNum: null,
        message: null,
        isSale: null,
        saleTime: null,
        goodsId: null,
        orderType: null,
        kjIs: null,
        jfKjIs: null,
        luckNo: null,
        minType: null,
        give: null,
        insurance: null,
        creator: null,
        createDate: null,
        type: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      console.log();
      this.reset();
      const id = row.id || this.ids;
      this.good_value = row;
      if (row.originOrderJson) {
        this.good_list = JSON.parse(row.originOrderJson);
        //计算总价
        this.good_list.forEach((item) => {
          item.total = item.goodsPrice * item.num;
        });
      }else{
        this.good_list = [];
      }

      console.log(this.good_value);
      this.good_value_is = true;
      //跳转到详情页
      // 使用 Vue Router 进行页面跳转
      // this.$router.push({
      //   name: 'OrderXq', // 目标页面的路由名称
      //   params: { id },
      //   query: { data: encodedData }
      // });
      //传递对象到详情页
      // this.$tab.openPage(
      //   "查看[" + id + "]订单详情",
      //   "/order/order/list_xq/index/" + id
      // );
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateList(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addList(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除订单明细编号为"' + ids + '"的数据项？')
        .then(function () {
          return delList(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    handleReturnGoods(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认退货订单明细编号为"' + ids + '"的数据项？')
        .then(function () {
          const params = {
            id: ids,
            userId: row.userId,
          }
          return returnGoods(params);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("退货成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/list/export",
        {
          ...this.queryParams,
        },
        `list_${new Date().getTime()}.xlsx`
      );
    },
    //查询用户信息
    async queryUser(arr) {
      let val = arr;
      for (let index = 0; index < arr.length; index++) {
        console.log(arr[index].userId);
        await getMy_user(arr[index].userId).then((response) => {
          if (response.data) {
            this.$set(this.listList[index], "username", response.data.nickname);
            this.$set(this.listList[index], "headimg", response.data.headimg);
          }
        });
      }
    },
    //排序
    dataListSortChangeHandle(data) {
      if (!data.order || !data.prop) {
        this.queryParams.orderByColumn = "";
        this.queryParams.isAsc = "";
        return false;
      }
      this.queryParams.isAsc = data.order.replace(/ending$/, "");
      this.queryParams.orderByColumn = data.prop
        .replace(/([A-Z])/g, "_$1")
        .toLowerCase();
      this.getList();
    },
  },
};
</script>
